home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
cwscr.exe
/
MYSCR.CPP
< prev
next >
Wrap
Text File
|
1991-07-28
|
6KB
|
234 lines
/*
Text Screen module class specification.
This is the source file that contains the actual source to the
routines used to output text based information to the screen.
Library : mycpp.lib
*/
static char MyScr_Id[] = "myscr.cpp 1.00 05/22/91";
/*
Version notes :
1.00 - Original creation / release. ( 2-14-91 CW )
1.10 - Added scroll routines. Also changed all of the char * modifiers
to const char * where possible. ( 5-22-91 CW )
*/
#include <dos.h>
#include "myscr.h"
#define XMAX 80
#define YMAX 24
#define SCR_POS( scr, x, y ) ((scr_type far *)(scr) + ((x) + ((y) * 80)))
/* ------------------------------------------------------------------ */
void
myScreen::init(){
union REGS regs;
regs.h.ah = 15;
int86( 0x10, ®s, ®s );
int color = (( regs.h.al != 7 ) && ( regs.h.al != 96 ));
screen = (scr_type far *)( color ? 0xb8000000L : 0xb0000000L );
cursor_show();
}
/* .................................................................. */
void
myScreen::print( int x, int y, int attr, const char *str ){
tscr = SCR_POS( screen, x, y );
while( *str && ( ++x <= XMAX )){
if( attr != -1 )
tscr->attrib = attr;
(tscr++)->ch = *str++;
}
}
/* .................................................................. */
void
myScreen::print( int x, int y, int attr, const char chr ){
tscr = SCR_POS( screen, x, y );
if( attr != -1 )
tscr->attrib = attr;
(tscr++)->ch = chr;
}
/* .................................................................. */
void
myScreen::clear( int x, int y, int w, int h, int attr ){
while(( h-- > 0 ) && ( y < YMAX )){
tscr = SCR_POS( screen, x, y );
for( int i = 0; (i < w) && ((i + x) < XMAX); i++ ){
if( attr != -1 )
tscr->attrib = attr;
(tscr++)->ch = ' ';
}
y++;
}
}
/* .................................................................. */
void
myScreen::change( int x, int y, int w, int h, int attr ){
if( attr != -1 ){
while(( h-- > 0 ) && ( y < YMAX )){
tscr = SCR_POS( screen, x, y );
for( int i = 0; (i < w) && ((i + x) < XMAX); i++ ){
(tscr++)->attrib = attr;
}
y++;
}
}
}
/* .................................................................. */
void
myScreen::scroll( ScrollDir dir, int x, int y, int w, int h, const char *str ){
scr_type far *tscr2;
if( dir == Scroll_Up ){
for( int rows = 0; rows < ( h-1 ); rows++ ){
tscr = SCR_POS( screen, x, y + rows );
tscr2 = SCR_POS( screen, x, y + rows + 1 );
for( int cols = 0; cols < w; cols++ ){
*tscr++ = *tscr2++;
}
}
clear( x, y + h - 1, w, 1 );
if( strlen( str ) > 0 )
print( x, y + h - 1, str );
} else if( dir == Scroll_Down ){
for( int rows = ( h-1 ); rows >= 0; rows-- ){
tscr = SCR_POS( screen, x, y + rows );
tscr2 = SCR_POS( screen, x, y + rows - 1 );
for( int cols = 0; cols < w; cols++ ){
*tscr++ = *tscr2++;
}
}
clear( x, y, w, 1 );
if( strlen( str ) > 0 )
print( x, y, str );
}
}
/* .................................................................. */
const save_type *
myScreen::save( int x, int y, int w, int h ){
int save_size = w * h;
save_type *data;
data = new save_type;
data->x = x;
data->y = y;
data->w = w;
data->h = h;
data->scr_ptr = new scr_type[ save_size ];
scr_type *tptr = data->scr_ptr;
while(( h-- > 0 ) && ( y < YMAX )){
tscr = SCR_POS( screen, x, y );
for( int i = 0; (i < w) && ((i + x) < XMAX); i++ ){
*tptr++ = *tscr++;
}
y++;
}
return( data );
}
/* .................................................................. */
void
myScreen::restore( const save_type *data ){
int x = data->x;
int y = data->y;
int w = data->w;
int h = data->h;
scr_type *tptr = data->scr_ptr;
while(( h-- > 0 ) && ( y < YMAX )){
tscr = SCR_POS( screen, x, y );
for( int i = 0; (i < w) && ((i + x) < XMAX); i++ ){
*tscr++ = *tptr++;
}
y++;
}
}
/* .................................................................. */
/* .................................................................. */
void
myScreen::cursor_move( int x, int y ){
union REGS regs;
regs.h.ah = 2;
regs.h.bh = 0;
regs.h.dl = x;
regs.h.dh = y;
int86( 0x10, ®s, ®s );
}
/* .................................................................. */
void
myScreen::cursor_show(){
union REGS regs;
regs.h.ah = 1;
regs.h.ch = 7; // starting scan line.
regs.h.cl = 8; // ending scan line.
int86( 0x10, ®s, ®s );
cursor_flag = TRUE;
}
/* .................................................................. */
void
myScreen::cursor_hide(){
union REGS regs;
regs.h.ah = 1;
regs.x.cx = 0x2000;
int86( 0x10, ®s, ®s );
cursor_flag = FALSE;
}
/* ================================================================== */
#ifdef debug_screen
#include <conio.h> // for getch() function call.
main(){
myScreen theScreen;
theScreen.clear();
theScreen.clear( 1, 5, 15, 5, SCR_Fi_White | SCR_B_Green );
theScreen.print( 1, 5, "this is a test. this is a test. line 1" );
theScreen.print( 1, 6, "this is a test. this is a test. line 2" );
theScreen.print( 1, 7, "this is a test. this is a test. line 3" );
theScreen.print( 1, 8, "this is a test. this is a test. line 4" );
theScreen.print( 1, 9, "this is a test. this is a test. line 5" );
if( !getch() ) getch();
theScreen.scroll( Scroll_Up, 5, 3, 10, 5 );
if( !getch() ) getch();
theScreen.scroll( Scroll_Down, 5, 3, 10, 5 );
if( !getch() ) getch();
theScreen.scroll( Scroll_Up, 32, 5, 10, 5, " the line last." );
if( !getch() ) getch();
return 0;
}
#endif